<template>
    <div class="login-container">
        <h1>登录</h1>
      <el-form ref="loginForm" :model="loginForm" :rules="rules" label-width="100px">
        <el-form-item label="用户名" prop="username">
          <el-input v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密&nbsp&nbsp&nbsp&nbsp码" prop="password">
          <el-input type="password" v-model="loginForm.password"></el-input>
        </el-form-item>
        <el-form-item>
            <div class="button">
                <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
                <el-button @click="resetForm('loginForm')">重置</el-button>
            </div>
        </el-form-item>
      </el-form>
    </div>
</template>

<script>
  export default {
    data() {
      return {
        loginForm: {
          username: '',
          password: ''
        },
        rules: {
          username: [
            { required: true, message: '请输入用户名', trigger: 'blur' }
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' }
          ]
        }
      };
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            alert('登录成功!');
            this.$router.push('/index');
          } else {
            console.log('表单验证失败!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    }
  };
</script>

<style scoped>
.login-container {
  width: 400px;
  margin: 100px auto;
  padding: 20px;
  border: 1px solid #ccc;
  border-radius: 10px;
  background: #efefef;
}

.el-form-item {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  justify-content: center;
}

.el-form-item__label {
  width: 80px; /* 固定宽度，根据需要调整 */
  text-align: right; /* 右对齐 */
  margin-right: 20px; /* 标签和输入框之间的间距 */
  color: #333; /* 字体颜色 */
  font-weight: bold; /* 字体加粗 */
}

.el-input {
  flex-grow: 1; /* 输入框占据剩余空间 */
}

h1{
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 15px;
}

.el-button{
    margin-left: 25px;
}

a{
  display: flex;
  justify-content: right;
  font-size: 14px;
  color: #293c53;
  text-decoration: none;
}

a:hover{
  color: #0084ff;
}
</style>
